package com.autonavi.abs.common.util;

import org.apache.commons.codec.binary.Hex;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author wwy
 * @version V1.0
 * <p>Description: md5 util</p>
 * @date 2020-07-23 12:07
 */
public class Md5Utils {

    /**
     * 字符串转md5
     * @param data
     * @return
     */
    public static String md5(String data){
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("No MD5 algorithm available!");
        }

        return new String(Hex.encodeHex(digest.digest(data.getBytes())));
    }

}
